class Solution {
public:
    double myPow(double x, int n) {
        if(n<0){
            long long int tmp=-(long long int)n;
            return _pow(1/x,tmp);
        }
        return _pow(x,n);
    }

    double _pow(double x,long long n){
        if(n==0) return 1;
        double tmp=_pow(x,n/2);
        return n%2==0?tmp*tmp:tmp*tmp*x;
    }
};